//
//  LSZInformationDetailsVC.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/24.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZInformationDetailsVC.h"

@interface LSZInformationDetailsVC ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) UITableView * tableViewInformation;
@property(nonatomic,strong) NSMutableArray * mutArrayData;
@property(nonatomic,assign) NSInteger page;
@end

@implementation LSZInformationDetailsVC
#pragma mark - 获得请求数据
-(void)getInformationDetails:(NSInteger)page
{
    __weak typeof(self) weakSelf = self;
    [LSZRequestDicData secondaryInterfaceForData:self.id_id page:page :^(BOOL isOK, NSString * str, LSZSecondaryInterfaceManager * mg) {
        if (isOK == YES) {
            if(page == 0){
                [weakSelf.mutArrayData removeAllObjects];
                [weakSelf.mutArrayData addObjectsFromArray:mg.arrayData];
            }else{
                [weakSelf.mutArrayData addObjectsFromArray:mg.arrayData];
            }
            [weakSelf.tableViewInformation reloadData];
        }else{
            if ([str isEqualToString:@"重复登录"]) {
                [LSZPublicClassDataToll RepeatLoginInterfaceJump:self.view fromVC:@"LSZInformationDetailsVC"];
            }else{
                [LSZPublicClassDataToll initWithAlertKuangView:self.view string:str];
            }
        }
    }];
}
-(void)goToLogin
{
    [LSZPublicClassDataToll goToLogin];
}
-(void)addNotificationCenter
{
    NSString * strDelete = [NSString stringWithFormat:@"%@Login",@"LSZInformationDetailsVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLogin) name:strDelete object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    __weak typeof(self) weakSelf = self;
    [self addNotificationCenter];
    weakSelf.page = 0;
    weakSelf.mutArrayData = [[NSMutableArray alloc]init];
    [weakSelf.tableViewInformation registerClass:[LSZDocumentdetailsCell class] forCellReuseIdentifier:@"LSZDocumentdetailsCell"];
    [weakSelf getInformationDetails:self.page];
    /*
    [weakSelf.tableViewInformation addRefreshHeaderWithHandle:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.page = 0;
            [weakSelf getInformationDetails:self.page];
            [weakSelf.tableViewInformation.mj_header endRefreshing];
        });
    }];
    weakSelf.tableViewInformation.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.page++;
            [self getInformationDetails:self.page];
            [self.tableViewInformation.mj_footer endRefreshing];
        });
    }];
    */
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.001;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mutArrayData.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LSZDocumentdetailsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZDocumentdetailsCell" forIndexPath:indexPath];
    if (self.mutArrayData.count > indexPath.row) {
        LSZSecondaryInterfaceMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
        cell.secondaryInterfaceMg = mg;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.mutArrayData.count > indexPath.row) {
        LSZArticleDetailsMg * mg = nil;
        mg = self.mutArrayData[indexPath.row];
        LSZSecondaryLiteratureDetailsVC * vc = [[LSZSecondaryLiteratureDetailsVC alloc]init];
        vc.id_id = mg.id_id;
        vc.urlImageView = mg.coverUrl;
        vc.titleString = mg.name;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(UITableView *)tableViewInformation
{
    if (_tableViewInformation == nil) {
        _tableViewInformation = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , [[UIScreen mainScreen] bounds].size.height-44) style:UITableViewStyleGrouped];
        _tableViewInformation.delegate = self;
        _tableViewInformation.dataSource = self;
        _tableViewInformation.estimatedRowHeight=0;
        _tableViewInformation.estimatedSectionFooterHeight =0;
        _tableViewInformation.estimatedSectionHeaderHeight =0;
        [_tableViewInformation setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];
        [self.view addSubview:_tableViewInformation
         ];
    }
    return _tableViewInformation;
}

@end
